package dome1;

import java.util.Objects;

public class Person {
    private String name;
    private int age;

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object obj) {
        if(obj == null) {
            return false;
        }
        if(this == obj) {
            return true;
        }
        if(!(obj instanceof Person)) {
            return false;
        }
        Person person = (Person) obj;//向下转型,比较属性值
        return this.name.equals(person.name) && this.age == person.age;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name,age);
    }
}
